package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.home.domain.HomeBanner;
import com.ruoyi.home.service.IHomeBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页轮播图Controller
 *
 * @author ruoyi
 * @date 2024-03-23
 */
@Anonymous
@RestController
@RequestMapping("/home/banner")
public class HomeBannerController extends BaseController
{
    @Autowired
    private IHomeBannerService homeBannerService;

    /**
     * 查询首页轮播图列表
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeBanner homeBanner)
    {
        startPage();
        List<HomeBanner> list = homeBannerService.selectHomeBannerList(homeBanner);
        return getDataTable(list);
    }

    /**
     * 导出首页轮播图列表
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:export')")
    @Log(title = "首页轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeBanner homeBanner)
    {
        List<HomeBanner> list = homeBannerService.selectHomeBannerList(homeBanner);
        ExcelUtil<HomeBanner> util = new ExcelUtil<HomeBanner>(HomeBanner.class);
        util.exportExcel(response, list, "首页轮播图数据");
    }

    /**
     * 获取首页轮播图详细信息
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(homeBannerService.selectHomeBannerByBannerId(bannerId));
    }

    /**
     * 新增首页轮播图
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:add')")
    @Log(title = "首页轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeBanner homeBanner)
    {
        return toAjax(homeBannerService.insertHomeBanner(homeBanner));
    }

    /**
     * 修改首页轮播图
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:edit')")
    @Log(title = "首页轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeBanner homeBanner)
    {
        return toAjax(homeBannerService.updateHomeBanner(homeBanner));
    }

    /**
     * 删除首页轮播图
     */
//    @PreAuthorize("@ss.hasPermi('home:banner:remove')")
    @Log(title = "首页轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(homeBannerService.deleteHomeBannerByBannerIds(bannerIds));
    }
}
